package com.bobi.ecofavor.service.impl;

import com.bobi.ecofavor.model.domain.Goods;
import com.bobi.ecofavor.mapper.GoodsMapper;
import com.bobi.ecofavor.service.GoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品 服务实现类
 * </p>
 *
 * @author wenyuan
 * @since 2023-10-21
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    //根据store的id 查询goods中的部分数据
    @Override
    public List<Goods> getGoodsByStoreId(Integer storeId) {
        List<Goods> goods = goodsMapper.selectByStoreId(storeId);
        return goods;
    }


    /**
     * 根据订单编号恢复库存
     */
    @Override
    public void recoverStock(Integer orderId, Integer goodsNum) {
        goodsMapper.recoverStock(orderId, goodsNum);
    }

//    根据goods中的id查询goods相应数据和store的部分数据
    @Override
    public Goods getGAndSByGoodsId(Integer id) {
        Goods goods = goodsMapper.selectGAndSByGoodsId(id);
        return goods;
    }

    @Override
    public Double getPriceByGoodsId(Integer id) {
        double price1 = goodsMapper.selectPriceByGoodsId(id);
        return price1;
    }

}
